package com.learn.demo.ioc;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * 静态变量注入
 *
 * @author banjiawei
 * @date 2022/02/24
 */
@Component
@Slf4j
public class TestStaticIoc {
    private static String a;
    private static String b;

    public TestStaticIoc() {
    }

    @Autowired
    public TestStaticIoc(@Value("${test.static.a}") String a, @Value("${test.static.b}") String b){
        TestStaticIoc.a = a;
        TestStaticIoc.b = b;
    }

    @PostConstruct
    public void init(){
        log.info("a={}", a);
        log.info("=====================静态变量注入=====================");
        log.info("b={}", b);
        TestStaticIoc testStaticIoc = new TestStaticIoc();
        log.info("testStaticIoc is {}", testStaticIoc);
    }

    @Override
    public String toString() {
        return "TestStaticIoc{" +
                "a='" + a + '\'' +
                ", b='" + b + '\'' +
                '}';
    }
}
